/*
=============================================================
WebIntelligence(r) Report Panel
Copyright(c) 2001-2005 Business Objects S.A.
All rights reserved

Use and support of this software is governed by the terms
and conditions of the software license agreement and support
policy of Business Objects S.A. and/or its subsidiaries. 
The Business Objects products and technology are protected
by the US patent number 5,555,403 and 6,247,008

=============================================================
*/promptLabelDlgTitle = "提示";
promptLabelOkButtonCaption = "确定";
promptLabelApplyButtonCaption = "应用";
promptLabelRunQueryButtonCaption = "运行查询";
promptLabelWaitDlgTitle = "正在检索数据";
promptLabelRequireNPMessage = "当前提示的值列表需要以下提示的值："; 
promptLabelPromptsSummaryTitle = "提示摘要";
promptLablelFeedBackRerfreshMessage = "要查看列表的内容，请单击“刷新值”按钮。";
promptLablelNoValueMessage = "（--无值--）";
promptLabelPromptsSummaryTitle = "提示摘要";
promptLabelIntervalStartValue = "起始值";
promptLabelIntervalEndValue = "结束值";
promptLabelUseDefaultKeyDate = "使用默认日期";
promptLabelLovContextUnset = "上下文未设置";
promptLabelLovDelegateSearch = "使用搜索条件获取值。\n\n搜索区分大小写。搜索条件的示例如下：\n搜索 = a* -> 获取所有以“a”开头的值。\n搜索 = *a -> 获取所有以“a”结尾的值。\n搜索 = a*a -> 获取所有以“a”开头和结尾的值。\n搜索 = a*a* -> 获取所有以“a”开头并包含另一个“a”的值。";
iItemValueMaxLength=50;
initialized=false;
promptsDlg=null;
arrTreeViewMap=null;
prompts=new Array();
promptUI=null;
rangeValuesParams=null;
var ASPXExt=".aspx";
dlgWidth = 800;
dlgWidthMin = 550;
dlgHeight = 400;
dlgHeightMin = 270;
p.promptsDlgWidth=(p.promptsDlgWidth!=null)?p.promptsDlgWidth:dlgWidth;
p.promptsDlgHeight=(p.promptsDlgHeight!=null)?p.promptsDlgHeight:dlgHeight;
sepZoneWidth = dlgWidth-15;
sepZoneHeight = dlgHeight-80;
sepZonePos = Math.floor(sepZoneWidth/4);
leftZoneWidth = sepZonePos;
leftZoneHeight = sepZoneHeight;
leftZoneHeaderHeight = 21;  
rightZoneWidth = sepZoneWidth - sepZonePos;
rightZoneHeight = sepZoneHeight;
rightZoneHeaderHeight = 21;
selectedPromptIndex = -1;
keepPosElement = null;
customizedKeydate = new Array(); 
fromQP=false;
_this = null;
function loadDialog()
{
valueSep = (typeof(valueSep)=="undefined")?';':valueSep;
fromQP = (typeof(fromRunQuery)!="undefined" || typeof(fromQPPreview)!="undefined");
if (!initialized)
{
initialized = true;
promptsDlg = new_FrameDlgWidget({ id:"promptsDlg",type:_noNaviFrame,
title:promptLabelDlgTitle,
width:dlgWidth,height:dlgHeight,
frmWidth:dlgWidth, frmHeight:dlgHeight,
defaultCB:submitCB,
cancelCB:cancelCB});
promptsDlg.setResize(dlgResize,dlgWidthMin,dlgHeightMin);
splitZone = new_SplitZoneWidget({id:"PromptSplitZone",isHori:true,
resizeCB:szResizeCB,
width:sepZoneWidth,
height:sepZoneHeight,
pos:sepZonePos,
overflow:"hidden"});
splitZone.setMinimalDimensions(100,220);
pListWidget = new_TreeParameterWidget({id:"PromptList",
width:leftZoneWidth,
height:(leftZoneHeight-leftZoneHeaderHeight),
clickCB:pListWidgetCB,
doubleClickCB:pListWidgetCB});
promptAnswerZone = new_ScrolledZoneWidget({id:"promptAnswerZone",
borderW:1,padding:0,
w:rightZoneWidth,
h:(rightZoneHeight-rightZoneHeaderHeight)});
        lovZone = new ValueSelector({id:"promptLovZone"});
var strOkButtonLabel=(strSRC=="BCA")?((strWebApp=="cmc")?p._BtnLabelUpdate:promptLabelApplyButtonCaption):promptLabelRunQueryButtonCaption;
OKButton = promptsDlg.getOKBtn();
}
if (!promptsDlg.isHTMLSet())
{
	var arrHTML = new Array();
	var i = 0;
	arrHTML[i++]='<table style="background-color:#FFFFFF" width="100%" height="'+rightZoneHeight+'" border="0" cellspacing="0" cellpadding="0"><tbody>'
	arrHTML[i++]='<tr><td valign="top">'
	arrHTML[i++]= '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
	arrHTML[i++]=  '<tr><td height="21" style="background-image:url(\''+p._root+'images/flexdock.png\')">'
	arrHTML[i++]=   '<span id="promptNameID" style="padding-left:5px;color:#FFFFFF">'+promptLabelPromptsSummaryTitle+'</span>'
	arrHTML[i++]=  '</td></tr>'
	arrHTML[i++]=  '<tr><td valign="top">'
	//arrHTML[i++]=   pListWidget.getHTML()
	arrHTML[i++]=  '</td></tr>'
	arrHTML[i++]= '</table>';
	arrHTML[i++]='</td></tr>'
	arrHTML[i++]='</tbody></table>'
	splitZone.setFirstZoneHTML(arrHTML.join(''));
	arrHTML = new Array()
	var i = 0;
	arrHTML[i++]='<table id="promptRightZone" pos="'+sepZonePos+'" style="background-color:#FFFFFF" width="100%" height="'+leftZoneHeight+'" border="0" cellspacing="0" cellpadding="0"><tbody>'
	arrHTML[i++]='<tr><td valign="top">'
	arrHTML[i++]= '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
	arrHTML[i++]=  '<tr><td height="21" style="background-image:url(\''+p._root+'images/flexdock.png\')">'
	arrHTML[i++]=   '<span id="promptAnswerTitle" style="padding-left:5px;color:#FFFFFF;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:0px;display:block;">&nbsp;</span>'
	arrHTML[i++]=  '</td></tr>'
	arrHTML[i++]=  '<tr><td valign="top">'
	//arrHTML[i++]=   promptAnswerZone.beginHTML()
	arrHTML[i++]=    '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody>'
	arrHTML[i++]=     '<tr><td id="promptAnwerContainer" valign="top" style="padding:5px;display:none">'
	//arrHTML[i++]=      lovZone.getHTML()
	arrHTML[i++]=     '</td></tr>'
	arrHTML[i++]=    '</tbody></table>'
	//arrHTML[i++]=   promptAnswerZone.endHTML()
	arrHTML[i++]=  '</td></tr>'
	arrHTML[i++]= '</table>';
	arrHTML[i++]='</td></tr>'
	arrHTML[i++]='</tbody></table>'
	splitZone.setSecondZoneHTML(arrHTML.join(''));
	promptsDlg.setFrameHTML(splitZone.getHTML());
}
promptsDlg.init();
keepPosElement = _curDoc.getElementById("promptRightZone");
var pos = keepPosElement.getAttribute("pos");
//报错点
//lovZone.init();
//splitZone.init();
//promptAnswerZone.init();
//promptAnswerZone.css.overflow="hidden";
//pListWidget.init();
OKButton.setText(strOkButtonLabel);
OKButton.setDisabled(true);
OKButton.setTooltip(strOkButtonLabel);
//fillPromptsList();
if (p._appExt != ASPXExt)
{
topfs.hideWaitDlg();
}
promptsDlg.show(true);
//报错点2
//splitZone.resize(null, null, pos);
var _small=(winHeight() < p.promptsDlgHeight || winWidth() < p.promptsDlgWidth);
if (_small)
{
promptsDlg.resize((winWidth()<p.promptsDlgWidth?winWidth()-10:p.promptsDlgWidth),(winHeight()<p.promptsDlgHeight?winHeight():p.promptsDlgHeight));
//dlgResize((winWidth()<p.promptsDlgWidth?winWidth()-10:p.promptsDlgWidth),(winHeight()<p.promptsDlgHeight?winHeight():p.promptsDlgHeight));
}
else
{
if(winHeight() < dlgHeight || winWidth() < dlgWidth)
{
promptsDlg.resize((winWidth()<dlgWidth?winWidth()-10:dlgWidth),(winHeight()<dlgHeight?winHeight():dlgHeight));
//dlgResize((winWidth()<dlgWidth?winWidth()-10:dlgWidth),(winHeight()<dlgHeight?winHeight():dlgHeight));
}
else
{
promptsDlg.resize(dlgWidth,dlgHeight);
//dlgResize(dlgWidth,dlgHeight);
}
}
promptsDlg.layer.style.visibility = _hide;
promptsDlg.center();
promptsDlg.layer.style.visibility = _show;
}
function dlgResize(w,h)
{
splitZone.resize(w-15,h-80);
szResizeCB(splitZone);
}
function szResizeCB(o)
{
o=(o==null)?this:o;
var dim = o.getFirstZoneDimensions();
pListWidget.resize(dim.width, (dim.height-leftZoneHeaderHeight));
dim = o.getSecondZoneDimensions();
promptAnswerZone.resize((dim.width-1),(dim.height-rightZoneHeaderHeight));
lovZone.resize((dim.width-splitZone.getSplitThickness()-1),(dim.height-rightZoneHeaderHeight));
keepPosElement.setAttribute("pos", o.pos); 
var elTitle = _curDoc.getElementById("promptAnswerTitle");
if (elTitle)
elTitle.style.width = dim.width - 6;
}
function promptValuesToDisplayValues(inPromptValues)
{
var _SEPARATOR = ';';
var outString = '';
var caption = '';
if (inPromptValues == null || typeof(inPromptValues)=="undefined") return outString;
for (var j=0; j<inPromptValues.length; j++)
{
if (outString != '') outString += _SEPARATOR;
if (typeof(inPromptValues[j].path)!="undefined" && inPromptValues[j].path !=null && inPromptValues[j].path.length > 0){
caption =  getLastValueFromCaptionPath(inPromptValues[j].caption,inPromptValues[j].path);
}else{
caption = inPromptValues[j].caption;
}
outString += (inPromptValues[j].caption == '')? _emptyValueLab : caption;
}
return outString;
}
function getLastValueFromCaptionPath(captionPath,pathArray)
{
var _PATH_SEPARATOR ="\\";
var value ='';
if (typeof(captionPath) == "undefined" || captionPath == null || captionPath ==''){
return value;
}
if (typeof(pathArray) == "undefined" || pathArray == null || pathArray.length <= 0){
return captionPath;
}
var lastPathElem = pathArray[pathArray.length - 1];
var index = captionPath.lastIndexOf(_PATH_SEPARATOR + lastPathElem.caption + _PATH_SEPARATOR); 
value = captionPath.substr(index + lastPathElem.caption.length + 2 ,captionPath.length);
return value;
}
function concatDPNames(prompt)
{
if (typeof(prompt.dataproviderInfo)=='undefined') return '';
var dpNames = ' (';
for (var k=0; k<prompt.dataproviderInfo.length; k++)
{
if (k > 0) dpNames += ', ';
dpNames += prompt.dataproviderInfo[k].name;
}
dpNames += ')';
return dpNames;
}
function addQueriesNames()
{
for (var i=0; i<prompts.length; i++)
{
var pt=prompts[i];
for (var j=0; j<prompts.length; j++)
{
prompts[j].displayedQueriesNames = ''; 
if (i != j && prompts[j].id == pt.id && prompts[j].level == pt.level) 
{
prompts[j].displayedQueriesNames = concatDPNames(prompts[j]);
prompts[j].name += prompts[j].displayedQueriesNames;
}
}
}
}
function fillPromptsList()
{
var blnDisableOKButton = false;
var bItemToSelectFound = false;
for (var i=0; i<prompts.length; i++)
{
var pt=prompts[i];
pt.index = i;
pt.visible = true;
for (var j=0; j<i; j++)
{
if (prompts[j].id == pt.id && prompts[j].level != pt.level) 
{
pt.visible = false;
pt.originalIndex = prompts[j].index;
if (pt.level == 0)
prompts[j].isRequired = true;
break;
}
}
}
addQueriesNames();
pListWidget.deleteAll();
var groupedPrompts = new Array();
var gIndex = 1;
for (var i=0; i<prompts.length; i++)
{
var pt=prompts[i];
pt.isLovFilled = false;
pt.lovRefreshed = false;
pt.valueChanged = false;
pt.hasLOV = (pt.lov)?true:false;
pt.displayValues = null;
if (pt.values !=null && pt.values.length>0){
pt.displayValues = promptValuesToDisplayValues(pt.values);
}
if (pt.level == 0 && !pt.isOptional && pt.displayValues == null)
blnDisableOKButton = true;
if (pt.isKeydate)
{
pt.resetDependecies = false;
if (!isPromptKeyDateOnRefresh && pt.displayValues != null)
pt.visible = false;
}
if (pt.isSAPRegularVariable)
pt.resetDependecies = false;
if (pt.hasDefinitiveAnswer)
pt.visible = false;
if (pt.visible)
{
if (pt.groupIndex != gIndex)
{
pListWidget.addParameterGroup(groupedPrompts);
groupedPrompts = new Array();
gIndex = pt.groupIndex;
groupedPrompts[groupedPrompts.length] = pt;
}
else
groupedPrompts[groupedPrompts.length] = pt;
}
if (!bItemToSelectFound && pt.visible && (pt.level == 0 || (typeof(pt.isRequired) != "undefined" && pt.isRequired)))
{
itemToSelect = i;
bItemToSelectFound = true;
}
}
for (var i=prompts.length-1; i>=0; i--)
{
if (prompts[i].level == 0 && prompts[i].visible && prompts[i].dataproviderInfo != null)
{
for (var j=0; j<i; j++)
{
var pt = prompts[j];
if (pt.level == 0 && pt.visible && prompts[i].name == pt.name)
{
var dpName = '&nbsp(';
for (var k=0; k<prompts[i].dataproviderInfo.length; k++)
{
if (k > 0) dpName += ', ';
dpName += prompts[i].dataproviderInfo[k].name;
}
dpName += ')';
prompts[i].escapedName += dpName;
break;
}
}
}
}
pListWidget.addParameterGroup(groupedPrompts);
pListWidget.rebuildHTML();
if (bItemToSelectFound)
{
itemToSelect = (itemToSelect < 0)? 0 : itemToSelect; 
pListWidget.selectByData(itemToSelect);
}
OKButton.setDisabled(blnDisableOKButton);
}
function pListWidgetCB(iPrompt)
{
if (selectedPromptIndex != iPrompt)
{
selectedPromptIndex = iPrompt;
setTimeout('delayedpListWidgetCB('+iPrompt+')',10);
}
}
function delayedpListWidgetCB(iPrompt)
{
var pt = prompts[iPrompt];
checkKeydateChanges();
checkSAPVariableChanges();
setTimeout('updateDepDisplay('+pt.index+')',1);
var elTitle = _curDoc.getElementById("promptAnswerTitle");
if (elTitle)
{
var title = convStr(pt.name) + (pt.isOptional?'<span style="color:#cccccc">&nbsp;'+_promptOptional+'&nbsp;</span>':'');
elTitle.innerHTML = title;
}
var zoneType = _lovRightZoneType.basic;
if (pt.isKeydate && pt.defaultValues != null && pt.defaultValues.length > 0)
{
zoneType = _lovRightZoneType.customized;
if (customizedKeydate[iPrompt] == null)
customizedKeydateWidgets(iPrompt);
var lovZoneInfo = {"id":''+pt.index,
"rightZoneType": zoneType,
"customizedInfo": {"id":"customUI-"+pt.index,
"getHTMLCB":customizedKeydate_getHTML,
"initCB":customizedKeydate_Init,
"resizeCB":customizedKeydate_resize
}
}
lovZone.updateUI(lovZoneInfo);
}
else
{
if ((p._appExt == ASPXExt && pt.isKeydate )||(pt.answerType == 'Single' && !pt.hasLOV))
zoneType = _lovRightZoneType.oneTextField;
else if (pt.answerType == 'Interval')
zoneType = _lovRightZoneType.twoTextFields;
var lovID = (pt.hasLOV)?pt.lov.id:null;
var lovZoneInfo = {"id":''+pt.index,
"Uuid": (pt.key+'|'+lovID),
"isQueryLov": true,
"promptType": (pt.hasLOV && _userUseLov=='full')?((pt.isConstrained)?PromptType.constrained:PromptType.common):PromptType.free,
"promptIndex": iPrompt,
"rightZoneType": zoneType,
"selectionType": pt.type,
"dataType": pt.dataType,
"dateFormat": pt.inputFormat,
"selectMode": (pt.hasLOV)?pt.lov.selectMode:0,
"dsMemberSelectionMode": (pt.dataproviderInfo)?pt.dataproviderInfo[0].memberSelectionMode:null, 
"iDPIndex": strDPIndex,
"showRefresh": (_userRefreshLov=='full' && pt.hasLOV && pt.lov.isRefreshable && !pt.lov.isLovDelegatedSearch),
"lovActionCB": promptLovActionCB,
"updateLovCB": selectionChangedCB,
"getPromptsResponsesCB" : getPromptsResponsesCB,
"lovInfo": (pt.lov)?pt.lov:null,
"defaultValues": pt.values};
if (p._appExt == ASPXExt)
{
lovZoneInfo.promptName = pt.id;
if (pt.lov!=null && pt.lov.lastAction){lovZoneInfo.lastAction = pt.lov.lastAction;}
}
if (pt.answerType == 'Interval')
{
lovZoneInfo.rightTitle = promptLabelIntervalStartValue;
lovZoneInfo.endLabel = promptLabelIntervalEndValue; 
}
if (strSRC == 'BCA' || strSRC == 'RPV')
lovZoneInfo.extraParam = {"sEntry": strEntry,"iViewerID": iViewerID};
if (typeof(qpDPId)!="undefined")
{
    if (typeof(lovZoneInfo.extraParam)=="undefined")
    {
        lovZoneInfo.extraParam={}
    }
if (lovZoneInfo.extraParam)
{
lovZoneInfo.extraParam.qpDPId = qpDPId;
if (typeof(qpUuid)!="undefined")
{
    lovZoneInfo.extraParam.qpUuid = qpUuid; 
                }    
}
}
if (pt.hasLOV && _userUseLov=='full')
{
if (pt.lov.values == null || 
(typeof(pt.lov.values)!="undefined" &&  pt.lov.values.length <= 0) ) 
{
if (pt.lov.isLovDelegatedSearch)
lovZoneInfo.filterLOVBeforeUse = true;
else if (!pt.isSAPRegularVariable) 
lovZoneInfo.refreshLOVFirst = true;
}
if (pt.hasNP && !pt.isSAPRegularVariable) 
{
var isDelegateSeach = (pt.lov.isLovDelegatedSearch)?true:false;
if (isNPValueChanged(pt) || isDelegateSeach)
{
lovZoneInfo.parentNotFilled = !isDelegateSeach;
lovZone.updateUI(lovZoneInfo);
applyNPLovValues(pt,lovZoneInfo);
return;
}
else if (pt.lov.message)
{
var msg = pt.lov.message;
if (msg.type == 'NESTED_PROMPT' && msg.text == null)
{
msg.text = buildNPTextMessage(pt);
}
lovZoneInfo.parentNotFilled =  !isDelegateSeach;
lovZoneInfo.lovMsg = msg.text;
}
else if (pt.lov.values == null)
{
lovZoneInfo.parentNotFilled =  !isDelegateSeach;
lovZone.updateUI(lovZoneInfo);
applyNPLovValues(pt,lovZoneInfo);
displayLovSelector();
return;
}
}
if (pt.hasNP || pt.isSAPRegularVariable){
if (pt.isSAPRegularVariable && isNPValueChanged(pt)){ 
pt.lov.values = null;
}
var strResponse = getDependencyResponse(pt);
if (strResponse !='' && strResponse != '[]') {
if (lovZoneInfo.extraParam)
lovZoneInfo.extraParam.sPV = strResponse;
else
lovZoneInfo.extraParam = {sPV:strResponse};
}
}
lovZone.updateUI(lovZoneInfo);
if (pt.lov.message)
{
var msg = pt.lov.message;
if (msg.type == 'ERROR')
{
var msgTxt=(msg.text)?msg.text:p._VIEWER_ERR_DEFAULT;
lovZone.setLovMessage(msgTxt);
}
else if (msg.type == 'FEEDBACK_REFRESH')
lovZone.setLovMessage(promptLablelFeedBackRerfreshMessage);
else if (msg.type == 'NO_VALUE')
lovZone.setLovMessage(promptLablelNoValueMessage);
else if (msg.type == 'DELEGATE_SEARCH')
lovZone.setLovMessage(promptLabelLovDelegateSearch);
}
else if (pt.lov.values != null)
{
pt.lov.lastAction = 'F';
lovZone.updateLovContent(pt.lov);
pt.isLovFilled = true;
}
}
else
lovZone.updateUI(lovZoneInfo);
}
displayLovSelector();
}
function displayLovSelector()
{
var el = _curDoc.getElementById("promptAnwerContainer");
el.style.display = '';
if (p._appExt == ASPXExt  && pt.values){
if (p.hideWaitDlg)p.hideWaitDlg();
}
}
function getPromptsResponsesCB()
{
var arrResponse = new Array();
for (var i=0; i<prompts.length; i++)
{
var pt = prompts[i];
if (pt.level == 0)
{
var j = arrResponse.length;
arrResponse[j] = getPromptResponse(pt);
}
}
return arrResponse;
}
function customizedKeydateWidgets(iPrompt)
{
var pt = prompts[iPrompt];
var widgID = "CustomizedKeydate-" + iPrompt;
var dateFieldMaxWidth = 250;
var dateFieldMinWidth = 80;
if (typeof(customizedCalendarTextField)=="undefined") customizedCalendarTextField=new Array();
var dateField = customizedCalendarTextField[iPrompt] = new_CalendarTextFieldButton({id:"Date"+widgID, 
                                                width:dateFieldMaxWidth, 
                                                noMargin:true,
tooltip:pt.inputFormat,
                                                changeCB:customizedKeydate_changeCB,
keyUpCB:customizedKeydate_changeCB, 
                                                enterCB:customizedKeydate_changeCB});
dateField.setFormatInfo(pt.inputFormat);
dateField.setHelpTxt(pt.inputFormat);
dateField.maxWidth = dateFieldMaxWidth;
dateField.minWidth = dateFieldMinWidth;
if (typeof(customizedButton)=="undefined") customizedButton=new Array();
customizedButton[iPrompt] = new_ButtonWidget({id:"Button"+widgID,
label: promptLabelUseDefaultKeyDate,
width: 10,
clickCB:customizedKeydate_clickCB});
}
function customizedKeydate_getHTML()
{
var o = this;
var iPrompt = getCustomizedPromptIndex(o);
var arrHTML = new Array();
if (iPrompt >= 0)
{
customizedKeydate[iPrompt] = o;
var i = 0;
arrHTML[i++] = '<table id="customizedContainerID" style="margin-left:10px" border="0" cellspacing="0" cellpadding="0">';
arrHTML[i++] =  '<tr>';
arrHTML[i++] =   '<td>' + customizedCalendarTextField[iPrompt].getHTML() + '</td>';
arrHTML[i++] =   '<td width="10"></td>';
arrHTML[i++] =   '<td>' + customizedButton[iPrompt].getHTML() + '</td>';
arrHTML[i++] =  '</tr>';
arrHTML[i++] = '</table>';
}
return arrHTML.join('');
}
function customizedKeydate_Init()
{
var o = this;
var iPrompt = getCustomizedPromptIndex(o);
if (iPrompt >= 0)
{
customizedCalendarTextField[iPrompt].init();
customizedButton[iPrompt].init();
var pt = prompts[iPrompt];
customizedCalendarTextField[iPrompt].getTextField().setValue(pt.values[0].caption);
}
}
function customizedKeydate_resize(w,h)
{
var o = this.layer;
var iPrompt = getCustomizedPromptIndex(o);
if (iPrompt >= 0)
{
var dateField = customizedCalendarTextField[iPrompt];
o = customizedKeydate[iPrompt];
var table = _curDoc.getElementById("customizedContainerID");
if (!table.maxWidth)
{
table.maxWidth = table.offsetWidth ;
table.minWidth = (table.offsetWidth - dateField.maxWidth) + dateField.minWidth;
}
var rzWidth = (w-20); 
if (rzWidth < table.maxWidth && rzWidth >= table.minWidth)
{
var dx = table.maxWidth - rzWidth;
dateField.resize(dateField.maxWidth - dx);
}
else if (rzWidth < table.minWidth)
dateField.resize(dateField.minWidth);
}
}
function customizedKeydate_changeCB()
{
var o = this;
var selValues = new Array();
selValues[0] = new Object();
selValues[0].caption = o.text.getValue();
if (typeof(o.checkDate)!="undefined" && typeof(o.isDateValid)!="undefined" && typeof(o.isDateChecked)!="undefined")
{
selValues[0].checkDate = o.checkDate;
selValues[0].isDateValid = o.isDateValid;
selValues[0].isDateChecked = o.isDateChecked;
}
var iPrompt = getCustomizedPromptIndex(o);
if (iPrompt == selectedPromptIndex)
{
selectionChangedCB(selValues);
}
}
function customizedKeydate_clickCB()
{
var o = this;
var iPrompt = getCustomizedPromptIndex(o);
if (iPrompt >= 0)
{
var pt = prompts[iPrompt];
if (pt.defaultValues != null)
{
var selValues = pt.defaultValues;
customizedCalendarTextField[iPrompt].getTextField().setValue(selValues[0].caption);
selectionChangedCB(selValues);
checkKeydateChanges();
checkSAPVariableChanges();
}
}
}
function getCustomizedPromptIndex(o)
{
var iPrompt = -1;
var iPos = o.id.indexOf('-');
if (iPos >= 0)
iPrompt = o.id.substring(iPos+1);
return iPrompt;
}
function checkKeydateChanges()
{
var bReset = false;
for (var i=0; i<prompts.length; i++)
{
var pt=prompts[i];
if (pt.isKeydate && pt.resetDependecies)
{
bReset = true;
pt.resetDependecies = false;
var arr = getFactorizedPrompts(pt.index);
for (var k=0; k<arr.length; k++)
{
pt = arr[k];
var parentLevel = pt.level - 1;
for (var j=0; j<prompts.length; j++)
{
var ptc = prompts[j];
if (ptc.level == parentLevel && ptc.groupIndex == pt.groupIndex && ptc.key == pt.parentKey && ptc.values != null)
{
ptc.values = null;
ptc.displayValues =null;
ptc.valueChanged = true;
if (ptc.isSAPRegularVariable)
ptc.resetDependecies = true;
if (pListWidget.findByData(ptc.index) != null){
pListWidget.findByData(ptc.index).change(ptc.name,ptc.displayValues,ptc.isOptional);
}
}
}
}
}
}
if (bReset)
updateRunQueryButton();
return bReset;
}
function isNPValueChanged(pt)
{
var bChanged = false;
var arrDeps = getDependencies(pt);
if (pt.isSAPRegularVariable){
addSAPVarToDependencies(pt,arrDeps);
}
for (var i=0; i<arrDeps.length; i++)
{
var prompt = arrDeps[i];
if (!prompt.isOptional && prompt.valueChanged)
{
if (prompt.displayValues == null && prompt.dataType != 2)
{
pt.lov.message = new Object();
pt.lov.message.type = 'NESTED_PROMPT';
pt.lov.message.text = null;
bChanged = false;
break;
}
bChanged = true;
break;
}
}
return bChanged;
}
function hasMandatoryPrompt(pt)
{
var hasMdt = false;
var arrDeps = getDependencies(pt);
for (var i=0; i<arrDeps.length; i++)
{
var prompt = arrDeps[i];
if (!prompt.isOptional)
{
hasMdt = true;
break;
}
}
return hasMdt;
}
function applyNPLovValues(pt, lovZoneInfo)
{
showWt();
var strResponse = getDependencyResponse(pt);
if (lovZoneInfo.extraParam)
lovZoneInfo.extraParam.sPV = strResponse;
else
lovZoneInfo.extraParam = {sPV:strResponse};
lovZone.getFromSDK({sPV:strResponse,sAction:"R"}); 
}
function getDependencyResponse(pt)
{
var arrResponse = new Array();
var arrDeps = getDependencies(pt);
if (pt.isSAPRegularVariable){
addSAPVarToDependencies(pt,arrDeps);
}
for (var i=0; i<arrDeps.length; i++)
{
var prompt = arrDeps[i];
prompt.valueChanged = false;
var n = arrResponse.length;
arrResponse[n] = new Object();
arrResponse[n].id = prompt.id;
arrResponse[n].index = prompt.groupIndex;
arrResponse[n].key = prompt.key;
arrResponse[n].values = (prompt.values?prompt.values:new Array());
}
if (pt.isSAPRegularVariable)
{
for (var i=0; i<prompts.length; i++)
{
var psv = prompts[i];
if (psv.isSAPRegularVariable && !arePromptsEquals(pt,psv))
{
var isInList = false;
for (var j=0; j<arrResponse.length; j++)
{
if (psv.id == arrResponse[j].id)
{
isInList = true;
break;
}
}
if (!isInList)
{
var n = arrResponse.length;
arrResponse[n] = new Object();
arrResponse[n].id = psv.id;
arrResponse[n].index = psv.groupIndex;
arrResponse[n].key = psv.key;
arrResponse[n].values = (psv.values?psv.values:new Array());
}
}
}
}
return arrResponse.toJSON();
}
function updateDepDisplay(iPrompt)
{
var pt = prompts[iPrompt];
var arrDeps = getDependencies(pt);
pListWidget.updateParameterGroupDisplay(arrDeps, prompts);
}
function buildNPTextMessage(pt)
{
var arrHTML = new Array();
var i = 0;
arrHTML[i++] = '<table border="0" cellspacing="0", cellpadding="0">';
arrHTML[i++] =  '<tr><td>'+promptLabelRequireNPMessage+'</td></tr>'
arrHTML[i++] =  '<tr><td>';
arrHTML[i++] =   '<table border="0" style="margin-top:10px" width="100%" cellspacing="0" cellpadding="0">';
arrHTML[i++] =    '<tr><td><ul style="margin:0px;">';
var arrDeps = getDependencies(pt);
for (var j=0; j<arrDeps.length; j++)
{
var pt = arrDeps[j];
if ((pt.values==null || pt.values.length==0)&& !pt.isOptional)
{
arrHTML[i++] = '<li><a href="javascript:void(0)" onclick="'+_codeWinName+'.pListWidget.selectByData('+pt.index+')">'+pt.escapedName+'</a></li>';
}
}
arrHTML[i++] =    '</ul></td></tr>';
arrHTML[i++] =   '</table>';
arrHTML[i++] =  '</td></tr>';
arrHTML[i++] = '</table>';
return arrHTML.join('');
}
function checkSAPVariableChanges()
{
var bReset = false;
for (var i=0; i<prompts.length; i++)
{
var pt=prompts[i];
if (pt.isSAPRegularVariable && pt.resetDependecies)
{
bReset = true;
pt.resetDependecies = false;
var arr = getFactorizedPrompts(pt.index);
for (var k=0; k<arr.length; k++)
{
pt = arr[k];
for (var j=0; j<prompts.length; j++)
{
var ptc = prompts[j];
if (pt.isSAPRegularVariable && ptc.groupIndex == pt.groupIndex && ptc.key == pt.parentKey && ptc.values != null)
{
if (ptc.defaultValues != null && ptc.defaultValues.length >0){
ptc.values = ptc.defaultValues;
ptc.displayValues =  promptValuesToDisplayValues(ptc.defaultValues);
}else{
ptc.values = null;
ptc.displayValues =  null;
}
ptc.valueChanged = true;
ptc.resetDependecies = true;
if (pListWidget.findByData(ptc.index) != null){
pListWidget.findByData(ptc.index).change(ptc.name,ptc.displayValues,ptc.isOptional);
}
}
}
}
}
}
if (bReset)
updateRunQueryButton();
return bReset;
}
function promptLovActionCB(jsLov)
{
hideWt();
var pt = prompts[selectedPromptIndex];
pt.lov = jsLov;
pt.isLovFilled = true;
pt.lovRefreshed = (jsLov.lastAction == 'R')?true:pt.lovRefreshed;
var isDelegateSeach = (pt.lov.isLovDelegatedSearch)?true:false;
if (jsLov.message)
{
var msg = '';
if (jsLov.message.type == 'NESTED_PROMPT' && hasMandatoryPrompt(pt)) 
msg = buildNPTextMessage(pt);
else if (jsLov.message.type == 'FEEDBACK_REFRESH')
msg = promptLablelFeedBackRerfreshMessage;
else if (jsLov.message.type == 'NO_VALUE')
msg = promptLablelNoValueMessage;
else if (jsLov.message.type == 'ERROR')
msg = (jsLov.message.text)?jsLov.message.text:p._VIEWER_ERR_DEFAULT;
else if (jsLov.message.type == 'NEED_CONTEXT')
msg = promptLabelLovContextUnset;
else if (jsLov.message.type == 'DELEGATE_SEARCH' || isDelegateSeach)
{
msg = promptLabelLovDelegateSearch;
var searchWidget=lovZone.lovLeftZone.lovWidget.getLovSearch();
if (searchWidget!=null)
searchWidget.setSearchValue('');
}
lovZone.setLovMessage(msg);
}
}
function selectionChangedCB(selValues,lovZoneInfo)
{
if (lovZoneInfo != null && lovZoneInfo.promptIndex != selectedPromptIndex)
return;
var pt = prompts[selectedPromptIndex];
pt.values = selValues;
var lastValues = pt.displayValues;
pt.displayValues = null;
if (selValues.length == 1 && selValues[0].caption == '')
{
pt.displayValues = '';
pt.values = new Array();
}
else
{
if (selValues != null && selValues.length >0) {
                        pt.displayValues = promptValuesToDisplayValues(selValues);
                }
for (var i=0; i<selValues.length; i++)
{
if (selValues[i].checkDate && selValues[i].caption != '')
{
pt.checkDate = true;
if (i == 0)
{
pt.isDateValid = selValues[i].isDateValid;
pt.isDateChecked = selValues[i].isDateChecked;
}
else
{
pt.isDateValid = (pt.isDateValid && selValues[i].isDateValid);
pt.isDateChecked = (pt.isDateChecked && selValues[i].isDateChecked);
}
}
}
}
if(pt.answerType == 'Interval' && pt.displayValues == valueSep)
{
pt.displayValues = null;
}
pt.valueChanged = (lastValues != pt.displayValues)?true:pt.valueChanged;
pt.displayValues = (pt.displayValues=='')?null:pt.displayValues;
var xtraInfo=null;
if(isInvalidAnswer(pt)) 
{
xtraInfo={bInvalidAnswer:true};
}
pListWidget.findByData(selectedPromptIndex).change(pt.name,pt.displayValues,pt.isOptional,null,xtraInfo);
if ((p._appExt!=ASPXExt) && (pt.isKeydate && pt.valueChanged))
{
pt.resetDependecies = true;
checkKeydateChanges();
checkSAPVariableChanges();
}
if (pt.isSAPRegularVariable && pt.valueChanged)
{
pt.resetDependecies = true;
checkSAPVariableChanges();
}
synchronizeResponse(prompts,pt);
updateRunQueryButton();
}
function isInvalidAnswer(pt)
{
var ret = false;
if ((p._appExt==ASPXExt) && pt.isKeydate ) 
{
return ret;
}
if (pt.level == 0 && !pt.isOptional && pt.displayValues == null)
{
ret = true;
}
else if(pt.level == 0 && !pt.isOptional && pt.answerType == 'Interval' && pt.values)
{
for (var j=0;j<pt.values.length;j++)
{
if(pt.values[j].caption==null || pt.values[j].caption=='')
{
ret = true;
break;
}
if (pt.checkDate && pt.isDateChecked && !pt.isDateValid)
{
ret = true;
break;
}
}
}
else if (pt.checkDate && pt.isDateChecked)
{ 
ret=(pt.isOptional && pt.displayValues == null)?false:!pt.isDateValid;
}
return ret;
}
function updateRunQueryButton()
{
var disableOKButton=false;
for (var i=0; i<prompts.length; i++)
{
var pt = prompts[i];
if(isInvalidAnswer(pt))
{
disableOKButton = true;
break;
}
}
OKButton.setDisabled(disableOKButton);
}
function cancelCB()
{
promptsDlg.show(false);
finalize();
if (p.cancelRefreshOnOpen) {
p.cancelRefreshOnOpen()
}
if (strSRC=="BCA")
p.goBackSchedule();
else
{
    if(!fromQP)
    {
var url=p._root + "processCleanSession" + p._appExt; 
ajaxUpdater({"url":url,"sEntry":strEntry,"ajaxErrorCB":p.manageAjaxError});
    }
}
}
function finalize()
{
p.promptsDlgWidth=promptsDlg.width;
p.promptsDlgHeight=promptsDlg.height;
var l = promptsDlg.layer;
var f = document.frmPrompts;
f.parentNode.removeChild(f);
l.parentNode.removeChild(l);
prompts = null;
}
function submitCB()
{
	checkKeydateChanges();
	if (OKButton.isDisabled())
		return;
	checkSAPVariableChanges();
	if (OKButton.isDisabled())
		return;
	var arrResponse = new Array();
	for ( var i = 0; i < prompts.length; i++) {
		var pt = prompts[i];
		if (pt.level == 0) {
			var j = arrResponse.length;
			arrResponse[j] = getPromptResponse(pt);
		}
	}
	for ( var i = 0; i < arrResponse.length; i++) {
		var pt = arrResponse[i];
		synchronizeResponse(arrResponse, pt);
	}
	var promptForm = document.frmPrompts;
	promptForm.elements['sPV'].value = arrResponse.toJSON();
	promptForm.elements['sEmptyLab'].value = _emptyValueLab;
	promptsDlg.show(false);
	if (typeof (submitLovValuesCB) != "undefined") {
		submitLovValuesCB();
		return;
	}
	if (p._appExt != ASPXExt) {
		var url = 'processPrompts' + p._appExt;
		if (strSRC == 'BCA') {
			url += '?sEntry=' + strEntry + '&iViewerID=' + iViewerID + '&src='
					+ strSRC;
			if (p._viewerContext)
				url = p._viewerContext + '/' + url;
		} else if (strSRC == 'RPV')
			url += '?sEntry=' + strEntry + '&iViewerID=' + iViewerID + '&src='
					+ strSRC;
		else {
			url += p.urlParamsNoBID(strEntry, null, null, null, null, 1);
			url += '&sNEV=' + strNEV + '&sNewDoc=' + strNewDoc + '&viewType='
					+ strViewType;
			url += '&sApplyFormat=' + strApplyFormat + '&iDPIndex='
					+ strDPIndex + '&bValidateSQL=' + strValidateSQL
					+ '&nAction=' + nAction;
		}
		if (typeof (fromRunQuery) != "undefined") {
			url += "&fromRunQuery=" + fromRunQuery;
			if (typeof (widx) != "undefined") {
				url += "&widx=" + widx;
			}
			topfs.launchRefreshWaitDlg(promptLabelWaitDlgTitle, true, true,
					true);
		}
		if (typeof (fromQPPreview) != "undefined") {
			url += "&fromQPPreview=" + fromQPPreview;
			if (typeof (qpDPId) != "undefined") {
				url += "&qpDPId=" + qpDPId;
			}
			if (typeof (widx) != "undefined") {
				url += "&widx=" + widx;
			}
			showWt();
		}
		promptForm.action = url;
		promptForm.submit();
	} else {
		promptsDlg.show(false);
		p.goFinishSchedule(prompts);
	}
	var blnLovRefreshed = false;
	var blnValueChanged = false;
	for ( var i = 0; i < prompts.length; i++) {
		var pt = prompts[i];
		blnLovRefreshed = (blnLovRefreshed || pt.lovRefreshed);
		blnValueChanged = (blnValueChanged || pt.valueChanged);
	}
	if (strSRC != 'BCA' && strSRC != 'RPV') {
		var n = 0;
		var pHasNP = false;
		for ( var i = 0; i < iNbPrompts; i++) {
			var pt = prompts[i];
			if (pt.level == 0) {
				n++;
				pHasNP = (pHasNP || pt.hasNP);
			}
		}
		if (p.eventManager) {
			if (blnLovRefreshed) {
				if (pHasNP)
					p.eventManager.notify(p._EVT_PROMPTS_LOV_REFRESHED);
				else
					p.eventManager.notify(p._EVT_PROMPTS_LOV_REFRESHED, n);
			} else {
				p.eventManager.notify(p._EVT_PROMPTS_VALUES_CHANGED, n);
			}
			p.eventManager.notify(p._EVT_REFRESH_DATA);
		}
		topfs.launchRefreshWaitDlg(promptLabelWaitDlgTitle, true, true, true);
	} else if (p._appExt != ASPXExt) {
		showWt();
	}
	finalize();
}
function getPromptResponse(pt)
{
var response = new Object();
response.id = pt.id;
response.index = pt.groupIndex;
response.key = (pt.subKey)?pt.subKey:pt.key;
response.dataType = pt.dataType;
response.values = (pt.values!=null)?pt.values:new Array();
response.deps = getDepencyAnswers(pt);
response.dataproviderInfo = pt.dataproviderInfo;
return response;
}
function getDepencyAnswers(pt)
{
var arrResponse = new Array();
var arrDeps = getDependencies(pt);
for (var i=0; i<arrDeps.length; i++)
{
var ptc = arrDeps[i];
var j = arrResponse.length;
arrResponse[j] = getPromptResponse(ptc);
}
return arrResponse;
}
function getDependencies(pt)
{
var arrDeps = new Array();
var childrenLevel = pt.level + 1;
for (var i=0; i<prompts.length; i++)
{
var prompt = prompts[i];
if (prompt.groupIndex == pt.groupIndex && prompt.level == childrenLevel && prompt.parentKey == pt.key)
{
if (!isNaN(prompt.originalIndex))
{
var orgIndex = prompt.originalIndex;
prompt = prompts[orgIndex];
prompt.subKey = prompts[orgIndex].key;
}
arrDeps[arrDeps.length] = prompt;
}
}
return arrDeps;
}
function arePromptsEquals(pt1,pt2)
{
    var bEquals= false;
    if (pt1.id != pt2.id) return false;
for (var i = 0; i < pt1.dataproviderInfo.length;i++){
var dp = pt1.dataproviderInfo[i];
bEquals = false;
for (var k = 0; k < pt2.dataproviderInfo.length;k++){
if(dp.id == pt2.dataproviderInfo[k].id){
            bEquals = true;
break;
}
}
if (!bEquals){
break;
}
}
return bEquals;
}
function addSAPVarToDependencies(pt, arrDeps)
{
if (typeof(arrDeps)=="undefined" || null == arrDeps){
arrDeps = new Array();
}
for (var i=0; i<prompts.length; i++)
{
var prompt = prompts[i];
if (typeof(pt.isSAPRegularVariable)!="undefined" && pt.isSAPRegularVariable){
if (typeof(prompt.isSAPRegularVariable)!="undefined" && prompt.isSAPRegularVariable && !arePromptsEquals(pt,prompt)){
arrDeps[arrDeps.length] = prompt;
}
}
}
return arrDeps;
}
function synchronizeResponse(promptsList,pt)
{
for (var i=0; i<promptsList.length; i++)
{
var prompt = promptsList[i];
if (prompt.id == pt.id && prompt.level != pt.level)
{
prompt.values = (pt.values!=null)?pt.values:new Array();
prompt.displayValues = pt.displayValues;
}
else if ((typeof(prompt.deps)!="undefined") && prompt.deps.length>0)
{
synchronizeResponse(prompt.deps,pt);
}
}
}
function getFactorizedPrompts(iPrompt)
{
var arrFactorizedPrompts = new Array();
var pt = prompts[iPrompt];
if (pt)
{
var idx = pt.index;
for (var i=0; i<prompts.length; i++)
{
if (prompts[i].index == idx)
arrFactorizedPrompts[arrFactorizedPrompts.length] = prompts[i];
else if (!isNaN(prompts[i].originalIndex))
{
if (prompts[i].originalIndex == idx)
arrFactorizedPrompts[arrFactorizedPrompts.length] = prompts[i];
}
}
}
return arrFactorizedPrompts;
}
function hideWt()
{
if (p.hideWt)
p.hideWt();
else if (p.parent.hideWt)
p.parent.hideWt();
else if (topfs.hideWt)
topfs.hideWt();
}
function showWt()
{
if (p.wt)
p.wt();
else if (p.parent.wt)
p.parent.wt();
else if (topfs.wt)
topfs.wt();
}